﻿using MySqlSync.Core.Models;
using System.Data;

namespace MySqlSync.Core.Interfaces
{
    /// <summary>
    /// 数据库服务接口
    /// </summary>
    public interface IDbService
    {
        /// <summary>
        /// 执行查询，返回数据阅读器
        /// </summary>
        Task<IDataReader> ExecuteReaderAsync(string connectionString, string sql, params object[] parameters);

        /// <summary>
        /// 执行非查询操作
        /// </summary>
        Task<int> ExecuteNonQueryAsync(string connectionString, string sql,  object parameters);

        /// <summary>
        /// 获取表的全量数据
        /// </summary>
        Task<IEnumerable<SyncRecord>> GetAllRecordsAsync(string connectionString, string tableName, int batchSize, long lastId = 0);

        /// <summary>
        /// 获取表的增量数据
        /// </summary>
        Task<IEnumerable<SyncRecord>> GetChangedRecordsAsync(string connectionString, string tableName, DateTime lastSyncTime);

        /// <summary>
        /// 应用同步记录到目标数据库
        /// </summary>
        Task ApplySyncRecordAsync(SyncRecord record, string targetConnectionString);

        /// <summary>
        /// 获取表的主键列名
        /// </summary>
        Task<string> GetPrimaryKeyColumnNameAsync(string connectionString, string tableName);

        /// <summary>
        /// 检查表是否存在
        /// </summary>
        Task<bool> TableExistsAsync(string connectionString, string tableName);
    }
}
